home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / NURBs / Listing 3 - Bézier to NURB.c < prev   
Encoding:
C/C++ Source or Header  |  1995-11-20  |  1.2 KB  |  47 lines  |  [TEXT/CWIE]

  1. #include <QD3DGeometry.h>
  2. #include <QD3DMath.h>
  3.  
  4. #include <stdlib.h>
  5.  
  6.  
  7. typedef struct BezierCurve {
  8.     unsigned int    order;
  9.     TQ3Point3D        controlPoints[];
  10. } BezierCurve;
  11.  
  12. TQ3NURBCurveData *BezierToNURBCurve(BezierCurve *bezCurve)
  13. {
  14.     TQ3NURBCurveData    *nurbCurveData;            // NURB curve data structure
  15.     unsigned long        k;                        // Order of curve
  16.     TQ3Point3D            *b;                        // Bezier control point vector
  17.     unsigned long        i;                        // Control point or knot index
  18.     
  19.     // Set up local variables for readability.
  20.     k = bezCurve->order;
  21.     b = bezCurve->controlPoints;
  22.     
  23.     // Allocate data structure for new curve.
  24.     nurbCurveData = malloc(sizeof(TQ3NURBCurveData));
  25.     nurbCurveData->order = k;
  26.     nurbCurveData->numPoints = k;
  27.     nurbCurveData->controlPoints = malloc(k*sizeof(TQ3RationalPoint4D));
  28.     nurbCurveData->knots = malloc(2*k*sizeof(float));
  29.     
  30.     // Create the control points.
  31.     for (i = 0; i < k; i++) {
  32.         Q3RationalPoint4D_Set(&nurbCurveData->controlPoints[i],
  33.                                         b[i].x, b[i].y, b[i].z, 1.0);
  34.     }
  35.     
  36.     // Create the knots.
  37.     for (i = 0; i < k; i++) {
  38.         nurbCurveData->knots[i] = 0.0;
  39.         nurbCurveData->knots[i + k] = 1.0;
  40.     }
  41.     
  42.     // Set attributes here, if desired.
  43.     nurbCurveData->curveAttributeSet = NULL;
  44.     
  45.     return (nurbCurveData);
  46. }
  47.